package com.example.a10928.weifriend.ui.home.menu

import android.content.Intent
import android.databinding.ViewDataBinding
import android.support.v7.widget.GridLayoutManager
import android.view.View
import com.example.a10928.weifriend.App

import com.example.a10928.weifriend.R
import com.example.a10928.weifriend.adapter.UpdateVipAdapter
import com.example.a10928.weifriend.databinding.ActivityUpdateVipBinding
import com.example.a10928.weifriend.http.api.RowsWrapper
import com.example.a10928.weifriend.http.api.VariableName
import com.example.a10928.weifriend.http.api.base.UpvipPriceBean
import com.example.a10928.weifriend.http.api.base.VipSortBean
import com.example.a10928.weifriend.ui.BaseActivity
import com.example.a10928.weifriend.ui.DatabindingBaseActivity
import com.example.a10928.weifriend.util.RxUtil
import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.activity_update_vip.*

class UpdateVIPActivity : DatabindingBaseActivity() {

    var value:Double=0.0
    lateinit var adapter:UpdateVipAdapter
    var data:MutableList<VipSortBean.DataBean> = mutableListOf()
    override fun bindingInitData() {

    }

    override fun bindingInitView(viewDataBinding: ViewDataBinding) {
        setTitleText(BaseActivity.ThemeEnum.Back_Default, "升级VIP会员")
        val mBinding = viewDataBinding as ActivityUpdateVipBinding
        mBinding.view = this
        getUpvipPrice()
    }


    fun getUpvipPrice(){

        adapter = UpdateVipAdapter(R.layout.item_update_vip,data)

        adapter.setOnItemClickListener { adapter, view, position ->

            buyVip(position)


        }

        recyc.adapter=adapter
        recyc.layoutManager=GridLayoutManager(this,2)

        App.app().getBpService().get_vip_data()
                .compose(RxUtil.io2mainLoad(this))
                .subscribe(
                        Consumer {

                            data.clear()
                            data.addAll(it.data)
                            adapter.notifyDataSetChanged()

                        }, Consumer<Throwable> { RxUtil.errorException(it) }
                )

    }


    override fun bindingGetContentView(): Int {
        return R.layout.activity_update_vip
    }

    public fun onViewClick(v : View){
        when (v.id) {


            //    buyVip()


        }
    }

    private fun buyVip( position:Int){
        var intent :Intent = Intent(this,PaySelectActvitiy::class.java)
        intent.putExtra(PaySelectActvitiy.SOURCE_PAYSELECTACTIVITY_TYPE,PaySelectActvitiy.SOURCE_VIP_ACTIVITY);
        intent.putExtra(PaySelectActvitiy.DATA_VIP_ACTIVITY,data.get(position).price)
        intent.putExtra(VariableName.TYPE,data.get(position).id)
        startActivity(intent)
    }
}

